<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('论坛主题列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <style type="text/css">
        .td_nowrap {
            white-space:nowrap;/* 不换行 */
            overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
            text-overflow:ellipsis;/* 当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用。*/
        }
    </style>
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 论坛版块
                </div>
                <div class="box-tools pull-right">
                    <a type="button" class="btn btn-box-tool menuItem" href="#" onclick="block_manager()"
                       title="管理版块"><i
                            class="fa fa-edit"></i></a>
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                            class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                            class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新版块"><i
                            class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
</div>

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <input type="hidden" id="moduleId" name="moduleId">
                    <input type="hidden" id="parentId" name="parentId">
                    <div class="select-list">
                        <ul>
                            <li>
                                主题标题：<input type="text" name="topicTitle"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="bbs:topic:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()"
                   shiro:hasPermission="bbs:topic:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
                   shiro:hasPermission="bbs:topic:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('bbs:topic:edit')}]];
    var removeFlag = [[${@permission.hasPermi('bbs:topic:remove')}]];
    var prefix = ctx + "bbs/topic";

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        queryTopicList();
        queryBlockAndModuleTree();
    });

    function queryTopicList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "主题",
            columns: [{
                checkbox: true
            },
                {
                    field: 'topicId',
                    title: '主题ID'
                },
                {
                    field: 'moduleTitle',
                    title: '栏目标题',
                    class: 'td_nowrap'
                },
                {
                    field: 'topicTitle',
                    title: '主题标题',
                    class: 'td_nowrap'
                },
                {
                    field: 'topicImage',
                    title: '主题主图',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push("<img width='27px' height='27px' src='" + value + "'/>");
                        return actions.join('');
                    }
                },
                {
                    field: 'topicType',
                    title: '主题类型',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value === 0) {
                            //普通
                            actions.push("<span class=\"badge badge-info\">普通</span>");
                        } else if (value == 1) {
                            //精华
                            actions.push("<span class=\"badge badge-success\">精华</span>");
                        } else if (value == 2) {
                            //置顶
                            actions.push("<span class=\"badge badge-warning\">置顶</span>");
                        } else {
                            //普通
                            actions.push("<span class=\"badge badge-info\">普通</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'tag',
                    title: '标签'
                },
                {
                    field: 'status',
                    title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value === 0) {
                            //正常
                            actions.push("<span class=\"badge badge-primary\">正常</span>");
                        } else {
                            //关闭
                            actions.push("<span class=\"badge badge-danger\">关闭</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'viewCount',
                    title: '关注数',
                    align: 'center'
                },
                {
                    field: 'commentCount',
                    title: '回复数',
                    align: 'center'
                },
                {
                    field: 'createBy',
                    title: '创建者'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    // class: 'td_nowrap',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    class: 'td_nowrap',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.topicId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.topicId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    function queryBlockAndModuleTree() {
        var url = ctx + "bbs/topic/treeData";
        var options = {
            url: url,
            expandLevel: 1,
            onClick: zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#moduleId").val(treeNode.id);
            $("#parentId").val(treeNode.pId);
            $.table.search();
        }
    }

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function () {
        queryBlockAndModuleTree();
    });

    /* 主题管理-版块 */
    function block_manager() {
        var url = ctx + "bbs/block";
        $.modal.openTab("版块管理", url);
    }


</script>
</body>
</html>